<script>
  import $ from '../dfish.js'
  import TableAbs from './TableAbs.vue'
  import TableFixedLeft from './TableFixedLeft.vue'
  import TableFixedRight from './TableFixedRight.vue'
  import {
    h
  } from 'vue'

  export default {
    name: 'w-table',
    mixins: [TableAbs],
    props: ['face', 'scroll-x', 'scroll-y'],
    data() {
      return {
        leftTable: null,
        rightTable: null,
        scrollTable: null,
        scrollHover: false,
        fixedWidth: '',
      }
    },
    methods: {
      setLeftTable(left) {
        this.leftTable = left
      },
      setRightTable(right) {
        this.rightTable = right
      },
      html_slots() {
        return [this.slotHooks.thead, this.slotHooks.tbody, this.slotHooks.hiddens || [], this.fixedLeft || [], this.fixedRight || []]
      },
    },
    computed: {
      fixedLeft() {
        if (this.colgroup.findIndex(v => v.fixed == 'left') > -1) {
          return h(TableFixedLeft, null, this.$slots)
        }
      },
      fixedRight() {
        if (this.colgroup.findIndex(v => v.fixed == 'right') > -1) {
          return h(TableFixedRight, null, this.$slots)
        }
      },
      html_style() {
        return this.fixedWidth && {
          '--w-table-fixed-width': this.fixedWidth
        }
      }
    }
  }
</script>

<style>
  .w-table {
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
  }

  .w-table-tbl {
    table-layout: fixed;
    width: 100%;
    border-collapse: collapse;
  }

  .w-thead {
    background: var(--w-thead-background-color);
    overflow: hidden;
    flex-shrink: 0;
  }

  .w-tr {
    height: 40px;
  }

  .w-tbody .w-td {
    border-bottom: 1px solid var(--w-td-border-color);
    overflow: hidden;
  }

  .w-tbody .w-tr.z-on {
    background-color: #DFE3FF;

  }

  .w-tbody.z-br .w-td {
    white-space: normal;
    word-break: break-all;
    word-wrap: normal;
    overflow: visible;
  }

  .w-th {
    font-weight: normal;
  }

  .w-th-title {
    cursor: pointer;
  }

  .w-th-sort {
    height: 28px;
    line-height: 1;
    color: #aaa;
    cursor: pointer;
  }

  .w-th-sort-up:before {
    position: relative;
    top: 1px;
  }

  .w-th-sort-down:before {
    position: relative;
    top: -4px;
  }

  .w-th.z-asc .w-th-sort-up {
    color: var(--w--focus-color);
  }

  .w-th.z-desc .w-th-sort-down {
    color: var(--w--focus-color);
  }

  .w-td {
    padding: 5px;
    white-space: nowrap;
    word-break: keep-all;
    word-wrap: normal;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .w-td.z-align-left {
    text-align: left;
  }

  .w-td.z-align-center {
    text-align: center;
  }

  .w-td.z-align-right {
    text-align: right;
  }

  .w-td.z-valign-top {
    vertical-align: top;
  }

  .w-td.z-valign-middle {
    vertical-align: middle;
  }

  .w-td.z-valign-bottom {
    vertical-align: bottom;
  }

  .w-td>.w-triplebox>.w-input,
  .w-td>.w-radio>.w-input {
    min-height: auto;
  }

  .w-table-fixed-left {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    overflow: hidden;
    background-color: #fff;
  }

  .w-table-fixed-right {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    align-items: flex-end;
    overflow: hidden;
    background-color: #fff;
  }

  .w-tbody.z-scroll-x-show~.w-table-fixed-left,
  .w-tbody.z-scroll-x-show~.w-table-fixed-right {
    box-shadow: 0 0 10px rgb(0 0 0 / 12%);
  }

  .w-tbody.z-scroll-x-show[w-scroll-x=left]~.w-table-fixed-left,
  .w-tbody.z-scroll-x-show[w-scroll-x=right]~.w-table-fixed-right {
    box-shadow: none;
  }

  .w-table-fixed-left>.w-tbody>.w-scrollbar-y,
  .w-table-fixed-right>.w-tbody>.w-scrollbar-y {
    display: none;
  }

  .w-table-fixed-left .w-table-tbl,
  .w-table-fixed-right .w-table-tbl {
    width: var(--w-table-fixed-width);
  }

  .w-table.z-face-cell {
    border: 1px solid var(--w-table-border-color);
  }

  .w-table.z-face-cell .w-td {
    border: 1px solid var(--w-td-border-color, var(--w-table-border-color));
  }

  .w-table.z-face-cell .w-td:first-child {
    border-left: 0;
  }

  .w-table.z-face-cell .w-td:last-child {
    border-right: 0;
  }

  .w-table.z-face-cell .w-tr:first-child .w-td {
    border-top: 0;
  }

  .w-table.z-face-cell .w-tbody {
    margin-bottom: -1px;
  }
</style>
